package com.fjn.aopanno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//增强类
@Component
@Aspect //生成代理对象
public class UserProxy {
    //相同切入点的抽取(把被增强类中的公共部分取出来)
    @Pointcut(value = "execution(* com.fjn.aopanno.User.add(..))")
    public void pointCut(){}
    //前置通知
    //@Before注解表示作为前置通知
    @Before(value = "pointCut()")
    public void brfore(){
        System.out.println("before........");
    }
    //最终通知(方法执行后执行,有异常还是会执行)
    @After(value = "execution(* com.fjn.aopanno.User.add(..))")
    public void after(){
        System.out.println("after.......");
    }
    //后置通知(返回通知)(1.返回返回值后执行2.有异常不执行)
    @AfterReturning(value = "execution(* com.fjn.aopanno.User.add(..))")
    public void afterReturning(){
        System.out.println("afterReturning.......");
    }
    //异常通知(当你方法有异常才执行)
    @AfterThrowing(value = "execution(* com.fjn.aopanno.User.add(..))")
    public void afterThrowing(){
        System.out.println("afterThrowing......");
    }
    //环绕通知(在方法之前和之后都执行)
    @Around(value = "execution(* com.fjn.aopanno.User.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕之前........");
        proceedingJoinPoint.proceed();//被增强方法执行
        System.out.println("环绕之后.......");
    }
}
